package org.dromara.common.mongo.config;

import org.dromara.common.mongo.convert.BigDecimalToDoubleConverter;
import org.dromara.common.mongo.convert.DoubleToBigDecimalConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Stars
 * @Date: 2023/6/8 23:19
 */
@Configuration
@ComponentScan("org.dromara.common.mongo")
public class AutoApplication {


    /**
     * mongoCustomConversions会由spring进行管理,
     * 按照加入的转换器,在数据库读写时对数据类型进行转换
     *
     * @return
     */
    @Bean
    public MongoCustomConversions mongoCustomConversions() {
        List<Converter<?, ?>> converterList = new ArrayList<>();
        converterList.add(new BigDecimalToDoubleConverter());
        converterList.add(new DoubleToBigDecimalConverter());
        return new MongoCustomConversions(converterList);
    }
}
